package com.yunzheng.studyLeaveSystem.modules.user.user_info.servlet; /**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/03/20/18:25
 * @Description:
 */

import com.alibaba.fastjson.JSON;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import com.yunzheng.studyLeaveSystem.modules.user.user_info.service.User_infoService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
/*
 *将该用户头像旁信息传递给前端
 */
@WebServlet(name = "inforServlet", value = "/inforServlet")
public class inforServlet extends HttpServlet {
    private User_infoService user_infoService = new User_infoService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        session.setAttribute("id",7);
        int id = (int) session.getAttribute("id");
        String query = null;
        try {
            query = user_infoService.query(id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        ResponseWrapper success = ResponseWrapper.Success(query);
        String s = JSON.toJSONString(success);
        response.getWriter().write(s);
        System.out.println(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
    }
}
